import request from './request';
var util = require('./util.js');

request.config.baseURL = util.getApiUrl();

function fail(res) {
	uni.showModal({
		title: '提示',
		content: '网络错误或服务器异常，请稍后再试！',
		success: function(res) {
			if (res.confirm) {
				console.log('用户点击确定');
			} else if (res.cancel) {
				console.log('用户点击取消');
			}
		}
	});
	return res;
}

function success(res) {
	if (res.status == 200) {

	} else {
		uni.showModal({
			title: '提示',
			content: res.message,
			showCancel: false,
		});
		if (res.status == 777 || res.status == 778) {
			uni.clearStorageSync();
		}
	}
	return res;
}

var get_headers = () => {
	let getJosn = {
		headers: {
			"content-type": "application/json"
		}
	}
	return getJosn
}

const api = {
	baseURL: util.getApiUrl(),
	//小程序登录
	userWaLogin: (data, headers = get_headers()) => request.post('user/waLogin', data, headers).then(success).catch(fail),
	//用户详情
	userMy: (data, headers = get_headers()) => request.post('user/my', data, headers).then(success).catch(fail),
	//标签列表
	tagsList: (data, headers = get_headers()) => request.post('tags/list', data, headers).then(success).catch(fail),
	//知识库列表
	knowledgeList: (data, headers = get_headers()) => request.post('knowledge/list', data, headers).then(success).catch(fail),
	//查看知识库详情
	knowledgeDetail: (data, headers = get_headers()) => request.post('knowledge/detail', data, headers).then(success).catch(fail),
	//base64上传文件，参数base64str
	base64Upload: (data, headers = get_headers()) => request.post('file/base64Upload', data, headers).then(success).catch(fail),
	//更新用户信息
	userUpdateUserInfo: (data, headers = get_headers()) => request.post('user/updateUserInfo', data, headers).then(success).catch(fail),
	//用户收藏
	userFav: (data, headers = get_headers()) => request.post('user/fav', data, headers).then(success).catch(fail),
	//用户取消收藏
	userFavCancel: (data, headers = get_headers()) => request.post('user/favCancel', data, headers).then(success).catch(fail),
	//知识库收藏
	knowledgeFav: (data, headers = get_headers()) => request.post('knowledge/fav', data, headers).then(success).catch(fail),
	//知识库取消收藏
	knowledgeFavCancel: (data, headers = get_headers()) => request.post('knowledge/favCancel', data, headers).then(success).catch(fail),

	//开户
	bankAccountOpen: (data, headers = get_headers()) => request.post('bank/accountOpen', data, headers).then(success).catch(fail),
	//开户短信验证重发
	bankAccountOpenResend: (data, headers = get_headers()) => request.post('bank/accountOpenResend', data, headers).then(success).catch(fail),
	//开户短信验证
	bankAccountOpenVerify: (data, headers = get_headers()) => request.post('bank/accountOpenVerify', data, headers).then(success).catch(fail),
	//开户信息
	bankAccount: (data, headers = get_headers()) => request.post('bank/account', data, headers).then(success).catch(fail),
	//查询缴纳的诚意金
	bankSincer: (data, headers = get_headers()) => request.post('bank/sincer', data, headers).then(success).catch(fail),
	//缴存诚意金
	bankHold: (data, headers = get_headers()) => request.post('bank/hold', data, headers).then(success).catch(fail),
	//查询绑定的一类账户
	bankBindings: (data, headers = get_headers()) => request.post('bank/bindings', data, headers).then(success).catch(fail),
	//转账到诚意金账户
	bankTransfer: (data, headers = get_headers()) => request.post('bank/transfer', data, headers).then(success).catch(fail),
	//充值
	bankRecharge: (data, headers = get_headers()) => request.post('bank/recharge', data, headers).then(success).catch(fail),
	//提现
	bankWithdraw: (data, headers = get_headers()) => request.post('bank/withdraw', data, headers).then(success).catch(fail),
	//取消一类账户的绑定
	bankUnbinding: (data, headers = get_headers()) => request.post('bank/unbinding', data, headers).then(success).catch(fail),
	//绑定一类账户
	bankBinding: (data, headers = get_headers()) => request.post('bank/binding', data, headers).then(success).catch(fail),
	//已缴存的诚意金列表
	bankHolds: (data, headers = get_headers()) => request.post('bank/holds', data, headers).then(success).catch(fail),
	//楼盘列表
	buildingList: (data, headers = get_headers()) => request.post('building/list', data, headers).then(success).catch(fail),
	//楼盘详情
	buildingDetail: (data, headers = get_headers()) => request.post('building/detail', data, headers).then(success).catch(fail),
	//楼盘活动列表
	buildPromotionList: (data, headers = get_headers()) => request.post('buildPromotion/list', data, headers).then(success).catch(fail),
	// 楼盘活动详情
	buildPromotionDetail: (data, headers = get_headers()) => request.post('buildPromotion/detail', data, headers).then(success).catch(fail),
	// 看房预定检查
	buildingPreordainCheck: (data, headers = get_headers()) => request.post('building/preordainCheck', data, headers).then(success).catch(fail),
	// 看房预定
	buildingPreordain: (data, headers = get_headers()) => request.post('building/preordain', data, headers).then(success).catch(fail),
	//银行活动列表
	promotionList: (data, headers = get_headers()) => request.post('promotion/list', data, headers).then(success).catch(fail),

	// //订单附加内容支付
	timeCardVisit: (data, headers = get_headers()) => request.post('activity/timeCardVisit', data, headers).then(success).catch(fail),
	//新人时间卡详情
	timeCardNewcomer: (data, headers = get_headers()) => request.post('activity/timeCardNewcomer', data, headers).then(success).catch(fail),

}
export default api
